package util

import "math"

/**
 * @File : calc.go
 * @Description : 协程任务量计算
 * @Author : chen
 * @Date : 2024/4/9
 */
func CalcTask(avgNum int, taskNum int) (taskList []int) {
	corNum := int(math.Ceil(float64(taskNum) / float64(avgNum)))

	taskList = make([]int, corNum)
	avgTask := taskNum / corNum
	modTask := taskNum % corNum

	for i := 0; i < corNum; i++ {
		taskList[i] = avgTask
		if i < modTask {
			taskList[i] += 1
		}
	}
	return
}

// 二分搜索最优线程数量